package com.pmcc.core.service;

import com.pmcc.core.entity.City;
import com.pmcc.core.repository.CityRepository;
import com.pmcc.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by spurs on 2018/3/26.
 */
@Service
@Transactional
public class CityService {
    @Autowired
    CityRepository cityRepository;
//    @Autowired
//    DataSource dataSource;


    /**
     * 查询国家列表
     * @return ResultBean 通用的返回值对象
     */
    public ResultBean queryCountryCombo() {
//        System.out.println("--------max"+ dataSource.getMaxActive());
//        System.out.println("--------idle"+ dataSource.getMinIdle());
//        System.out.println("-----"+dataSource.getInitialSize());
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        try {
            List<City> list = cityRepository.queryCountryCombo();
            resultBean.setResultCode(ResultBean.SUCCESS);
            resultBean.setRows(list);
        } catch (Exception e) {
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }

    /**
     * 查询国家内的省份
     * @param id 实体id字段
     * @return ResultBean 通用的返回值对象
     */
    public ResultBean queryProvinceCombo(String id) {
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        try {
            List<City> list = cityRepository.queryProvinceCombo(id);
            resultBean.setResultCode(ResultBean.SUCCESS);
            resultBean.setRows(list);
        } catch (Exception e) {
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }

    /**
     * 查询省下面的市
     * @param id 实体id字段
     * @return ResultBean 通用的返回值对象
     */
    public ResultBean queryCityCombo(String id) {
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        try {
            List<City> list = cityRepository.queryCityCombo(id);
            resultBean.setResultCode(ResultBean.SUCCESS);
            resultBean.setRows(list);
        } catch (Exception e) {
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }

    /**
     * 查询市下面的区
     * @param id id 实体id字段
     * @return ResultBean 通用的返回值对象
     */
    public ResultBean queryAreaCombo(String id) {
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        try {
            List<City> list = cityRepository.queryAreaCombo(id);
            resultBean.setResultCode(ResultBean.SUCCESS);
            resultBean.setRows(list);
        } catch (Exception e) {
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }


}
